package com.dormitory.dao;

import com.dormitory.Util.C3P0Util;
import com.dormitory.entity.studentInformation;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
import com.dormitory.entity.*;
public class selectInformation {
    public  List<Object> getStudent(String s) throws  SQLException{
        List<Object> list= new ArrayList<>();
        Connection connection;
        Statement statement;
        ResultSet rs;
        try {
            connection = C3P0Util.getConnection();
            statement = connection.createStatement();
            rs = statement.executeQuery(s);
            while(rs.next()) {
                studentInformation student=new studentInformation();
                student.setId(rs.getString(1));
                student.setName(rs.getString(2));
                student.setSex(rs.getString(3));
                student.setSpno(rs.getString(4));
                student.setClassn(rs.getString(5));
                student.setBuilding(rs.getString(6));
                student.setBuildingnub(rs.getString(7));
                student.setFudao(rs.getString(8));
                student.setState(rs.getString(9));
                list.add(student);
            }
        } catch (SQLException e) {
            System.out.println("错误");
            throw new RuntimeException(e);
        }
        C3P0Util.release(connection,statement,rs);
        return list;
    }
    public void postStudent(String s){
        Connection connection;
        Statement statement;
        ResultSet rs = null;
        try {
            connection =C3P0Util.getConnection();
            statement = connection.createStatement();
            statement.executeUpdate(s);
        } catch (SQLException e) {
            System.out.println("错误");
            throw new RuntimeException(e);
        }
        C3P0Util.release(connection,statement,rs);
    }
    public  List<Object> getBuilding(String s) {
        List<Object> list= new ArrayList<>();
        Connection connection;
        Statement statement;
        ResultSet rs;
        try {
            connection = C3P0Util.getConnection();
            statement = connection.createStatement();
            rs = statement.executeQuery(s);
            while(rs.next()) {
                buildingInformation buildingInformation=new buildingInformation();
                buildingInformation.setBuilding(rs.getString(1));
                buildingInformation.setBuildingnub(rs.getString(2));
                buildingInformation.setState(rs.getString(3));
                list.add(buildingInformation);
            }
        } catch (SQLException e) {
            System.out.println("错误");
            throw new RuntimeException(e);
        }
        C3P0Util.release(connection,statement,rs);
        return list;
    }
    }


